package org.light.framework.service;

import java.util.List;

import org.light.framework.DataTableMediator;
import org.light.framework.EntityMediator;
import org.light.framework.bean.OperateResult;
import org.light.framework.bean.PageArgs;
import org.light.framework.bean.ResultColumn;
import org.light.framework.bean.ResultOrder;
import org.light.framework.bean.SearchArgs;
import org.light.framework.bean.UpdateColumn;
import org.light.framework.orm.DataTable;

/**
 * 业务组件基类
 * 
 * @author de.cel
 * @param <T>
 */
public abstract class BaseService<T> implements ITService<T> {

	@Override
	public OperateResult delete(Class<?> cls, String... ids) {
		return EntityMediator.delete(cls, ids);
	}

	@Override
	public int count(Class<T> cls) {
		return EntityMediator.count(cls, null);
	}

	@Override
	public int count(Class<T> cls, SearchArgs searchArgs) {
		return EntityMediator.count(cls, searchArgs);
	}

	@Override
	public int count(String tableOrViewName, SearchArgs searchArgs) {
		return DataTableMediator.count(tableOrViewName, searchArgs);
	}

	@Override
	public Double sum(Class<T> cls, String columnName, SearchArgs searchArgs) {
		return EntityMediator.sum(cls, columnName, searchArgs);
	}

	@Override
	public Double sum(String tableOrViewName, String columnName, SearchArgs searchArgs) {
		return DataTableMediator.sum(tableOrViewName, columnName, searchArgs);
	}

	@Override
	public DataTable getAll(String tableOrViewName, SearchArgs searchArgs, ResultOrder resultOrder) {
		return DataTableMediator.getAll(tableOrViewName, searchArgs, resultOrder, null);
	}

	@Override
	public DataTable getAll(String tableOrViewName, SearchArgs searchArgs, ResultOrder resultOrder,
			ResultColumn resultColumn) {
		return DataTableMediator.getAll(tableOrViewName, searchArgs, resultOrder, resultColumn);
	}

	@Override
	public DataTable search(String tableOrViewName, SearchArgs searchArgs, PageArgs pageArgs, ResultOrder resultOrder) {
		return DataTableMediator.getAll(tableOrViewName, searchArgs, resultOrder, null);
	}

	@Override
	public DataTable search(String tableOrViewName, SearchArgs searchArgs, PageArgs pageArgs, ResultOrder resultOrder,
			ResultColumn resultColumn) {
		return DataTableMediator.getAll(tableOrViewName, searchArgs, resultOrder, resultColumn);
	}

	@Override
	public OperateResult create(T obj) {

		return EntityMediator.create(obj);
	}

	@Override
	public OperateResult create(List<T> objs) {
		return EntityMediator.create(objs);
	}

	@Override
	public OperateResult delete(T obj) {
		return EntityMediator.delete(obj);
	}

	@Override
	public OperateResult delete(List<T> objs) {
		return EntityMediator.delete(objs);
	}

	@Override
	public OperateResult update(T obj) {
		return EntityMediator.update(obj);
	}

	@Override
	public OperateResult update(T obj, UpdateColumn uc) {
		return EntityMediator.update(obj, uc);
	}

	@Override
	public OperateResult update(List<T> objs) {
		return EntityMediator.update(objs);
	}

	@Override
	public OperateResult update(List<T> objs, UpdateColumn uc) {
		return EntityMediator.update(objs, uc);
	}

	@Override
	public T get(Class<T> cls) {
		try {
			return cls.newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public T get(Class<T> cls, String id) {
		return EntityMediator.get(cls, id);
	}

	@Override
	public T get(Class<T> cls, String id, ResultColumn resultColumn) {
		return EntityMediator.get(cls, id, resultColumn);
	}

	@Override
	public T get(Class<T> cls, SearchArgs searchArgs) {
		return EntityMediator.get(cls, searchArgs, null);
	}

	@Override
	public T get(Class<T> cls, SearchArgs searchArgs, ResultColumn resultColumn) {
		return EntityMediator.get(cls, searchArgs, resultColumn);
	}

	@Override
	public List<T> getAll(Class<T> cls) {
		return EntityMediator.getAll(cls, null, null, null);
	}

	@Override
	public List<T> getAll(Class<T> cls, int resultCount) {
		return EntityMediator.getAll(cls, null, null, null, resultCount);
	}

	@Override
	public List<T> getAll(Class<T> cls, ResultColumn resultColumn) {
		return EntityMediator.getAll(cls, null, null, resultColumn);
	}

	@Override
	public List<T> getAll(Class<T> cls, ResultColumn resultColumn, int resultCount) {
		return EntityMediator.getAll(cls, null, null, resultColumn, resultCount);
	}

	@Override
	public List<T> getAll(Class<T> cls, SearchArgs searchArgs) {
		return EntityMediator.getAll(cls, searchArgs, null, null);
	}

	@Override
	public List<T> getAll(Class<T> cls, SearchArgs searchArgs, int reslutCount) {
		return EntityMediator.getAll(cls, searchArgs, null, null, reslutCount);
	}

	@Override
	public List<T> getAll(Class<T> cls, SearchArgs searchArgs, ResultColumn resultColumn) {
		return EntityMediator.getAll(cls, searchArgs, null, resultColumn);
	}

	@Override
	public List<T> getAll(Class<T> cls, SearchArgs searchArgs, ResultColumn resultColumn, int reslutCount) {
		return EntityMediator.getAll(cls, searchArgs, null, resultColumn, reslutCount);
	}

	@Override
	public List<T> getAll(Class<T> cls, SearchArgs searchArgs, ResultOrder resultOrder) {
		return EntityMediator.getAll(cls, searchArgs, resultOrder, null);
	}

	@Override
	public List<T> getAll(Class<T> cls, SearchArgs searchArgs, ResultOrder resultOrder, int reslutCount) {
		return EntityMediator.getAll(cls, searchArgs, resultOrder, null, reslutCount);
	}

	@Override
	public List<T> getAll(Class<T> cls, SearchArgs searchArgs, ResultOrder resultOrder, ResultColumn resultColumn) {
		return EntityMediator.getAll(cls, searchArgs, resultOrder, resultColumn);
	}

	@Override
	public List<T> getAll(Class<T> cls, SearchArgs searchArgs, ResultOrder resultOrder, ResultColumn resultColumn,
			int resultCount) {
		return EntityMediator.getAll(cls, searchArgs, resultOrder, resultColumn, resultCount);
	}

	@Override
	public List<T> search(Class<T> cls, SearchArgs searchArgs, PageArgs pageArgs, ResultOrder resultOrder) {
		return EntityMediator.search(cls, searchArgs, pageArgs, resultOrder, null);
	}

	@Override
	public List<T> search(Class<T> cls, SearchArgs searchArgs, PageArgs pageArgs, ResultOrder resultOrder,
			ResultColumn resultColumn) {
		return EntityMediator.search(cls, searchArgs, pageArgs, resultOrder, resultColumn);
	}
}